package com.cyam.controller;

import java.util.HashMap;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.cyam.service.ArticleService;
import com.cyam.util.Pager;

@Controller
@RequestMapping("/search")
public class SearchController {

	@Resource
	private ArticleService articleService;
	
	@RequestMapping("/article")
	@ResponseBody
	public JSONObject listSearch(@RequestParam("keyword") String keyword,
			@RequestParam(value = "page",defaultValue = "1") int page,
			@RequestParam(value ="size",defaultValue = "8") int size) throws Exception{
		JSONObject result = new JSONObject();
		HashMap<String, Object> map = new  HashMap<String,Object>();
		map.put("keyword", keyword);
		Pager pageCount = articleService.searchCountArticle(map, 1, 8);
		Pager pager = articleService.searchListArticle(map,page,size);
		result.put("pageCount", pageCount);
		result.put("pager", pager);
		return result;
	}
}
